const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const app = express();

app.get('/', (req, res) => {
    res.send('Hello World!');
});

app.listen(3000, () => {
    console.log('示例应用正在监听 3000 端口 !');
});

MongoClient.connect('mongodb://localhost:27017/animals', (err, client) => {
    if (err) {
        throw err;
    }

    let db = client.db('动物');
    db.collection('哺乳动物').find().toArray((err, result) => {
        if (err) throw err;
        console.log(result);
        client.close();
    });
});

app.get('/', (req, res) => {
    res.render('index', { title: '关于狗狗', message: '狗狗很牛！' });
});